;(function ($) { $.fn.parallax_content = function () { var window_width = $(window).width(); // Parallax Scripts return this.each(function(i) { var section_height=$(this).height(); $(this).children().wrapAll('
'); var $this = $(this); //$this.addClass('parallax'); function updateContentParallax(resize) { var container_height=$this.height(); var parallax_dist=300; var bottom = $this.offset().top + container_height; var top = $this.offset().top; var scrollTop = $(window).scrollTop(); var windowHeight = window.innerHeight; var windowBottom = scrollTop + windowHeight; var percentScrolled = (windowBottom - top) / (container_height + windowHeight); var parallax = Math.round((parallax_dist * percentScrolled))-50; /* Assign height again */ if(resize) { $('.parallax-container',$this).height('auto'); $('.parallax-parent',$this).addClass('temp-parent').removeClass('parallax-parent'); $('.parallax-content',$this).addClass('temp-content').removeClass('parallax-content'); section_height=$('.parallax-container',$this).height(); $('.parallax-container',$this).css('height',section_height+'px'); $('.temp-parent',$this).addClass('parallax-parent'); $('.temp-content',$this).addClass('parallax-content'); } if ((bottom > scrollTop) && (top < (scrollTop + windowHeight))) { var $content=$('.parallax-content',$this); parallax=(scrollTop-top)/2; if(parallax < 0) { parallax=0; } $content.css('transform', "translate3D(-50%," + parallax + "px, 0)"); } } // Wait for image load $this.children("img").one("load", function() { updateContentParallax(false); }).each(function() { if(this.complete) $(this).load(); }); $(window).scroll(function() { window_width = $(window).width(); updateContentParallax(false); }); $(window).resize(function() { window_width = $(window).width(); updateContentParallax(true); }); }); }; $.fn.parallax = function () { var window_width = $(window).width(); // Parallax Scripts return this.each(function(i) { var $this = $(this); $this.addClass('parallax'); function updateParallax(initial) { var container_height; if (window_width < 601) { container_height = ($this.height() > 0) ? $this.height() : $this.children("img").height(); } else { container_height = ($this.height() > 0) ? $this.height() : 500; } var $img = $this.children("img").first(); var img_height = $img.height(); var parallax_dist = img_height - container_height; var bottom = $this.offset().top + container_height; var top = $this.offset().top; var scrollTop = $(window).scrollTop(); var windowHeight = window.innerHeight; var windowBottom = scrollTop + windowHeight; var percentScrolled = (windowBottom - top) / (container_height + windowHeight); var parallax = Math.round((parallax_dist * percentScrolled))-50; if (initial) { $img.css('display', 'block'); } if ((bottom > scrollTop) && (top < (scrollTop + windowHeight))) { $img.css('transform', "translate3D(-50%," + parallax + "px, 0)"); } } // Wait for image load $this.children("img").one("load", function() { updateParallax(true); }).each(function() { // if(this.complete) $(this).load(); }); $(window).scroll(function() { window_width = $(window).width(); updateParallax(false); }); $(window).resize(function() { window_width = $(window).width(); updateParallax(false); }); }); }; }( jQuery ));